#!/usr/bin/env python
# coding: utf-8

# #### 准备工作

# In[ ]:


import requests,json
import pandas as pd
zjy1022 = "7c59f691544a0b6d99863a1f42c6730d"


# ### 地理编码

# In[25]:


#定义函数geocode
#输入所有参数
def geocode(address, city=None, batch=None, sig=None, output=None, callback=None):
    #地理编码 API 服务地址
    url = 'https://restapi.amap.com/v3/geocode/geo?parameters' 
    params = {
        'key': zjy1022,
        'address': address,
        'city': city,
        'batch': batch,
        'sig': sig,
        'output': output, """响应结果的格式可以通过请求参数 output 指定，默认为 JSON 形式。"""
        'callback': callback
    }
#    url的请求方式是get
    response = requests.get(url, params= params) 
    data = response.json()
    return data


# ### 逆地理编码

# In[26]:


#定义函数regeocode
def regeocode(location, poitype=None, radius=None, extensions=None, batch=None, roadlevel=None, sig=None, output=None, callback=None, homeorcorp=None):
    #逆地理编码 API 服务地址
    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'
    params = {
        'key': zjy1022,
        'location': location,
        'poitype': poitype,
        'radius': radius,
        'extensions': extensions,
        '''extensions 参数默认取值是 base，也就是返回基本地址信息；
        extensions 参数取值为 all 时会返回基本地址信息、附近 POI 内容、道路信息以及道路交叉口信息。'''
        'batch': batch,
        'roadlevel': roadlevel,
        'homeorcorp': homeorcorp,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    #    url的请求方式是get
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 路径规划

# #### 步行路径规划

# In[27]:


#定义函数walking
def walking(origin, destination, sig=None, output=None, callback=None):
    #步行路径规划API URL
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    params = {
        'key': zjy1022,
        'origin': origin,
        'destination': destination,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# #### 公交路径规划

# In[28]:


#定义函数transit
def transit(origin, destination, city, cityd=None, extensions=None, strategy=None, nightflag=None, date=None, time=None, sig=None, output=None, callback=None):
    #公交路径规划API URL：
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    params = {
        'key': zjy1022,
        'origin': origin,
        'destination': destination,
        'city': city,
        'cityd': cityd,
        'extensions': extensions,
        'strategy': strategy,
        'nightflag':nightflag,
        'date': date,
        'time': time,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# #### 驾车路径规划

# In[29]:


#定义函数driving
def driving(origin, destination, extensions, originid=None, destinationid=None, origintype=None, destinationtype=None, strategy=None, waypoints=None, avoidpolygons=None, province=None, number=None, cartype=None, ferry=None, roadaggregation=None, nosteps=None, sig=None, output=None, callback=None):
    #驾车路径规划API URL：
    url = 'https://restapi.amap.com/v3/direction/driving?parameters'
    params = {
        'key':zjy1022,
        'origin':origin,
        'destination':destination,
        'originid':originid,
        'destinationid':destinationid,
        'origintype':origintype,
        'destinationtype':destinationtype,
        'strategy':strategy,
        'waypoints': waypoints,
        'avoidpolygons':avoidpolygons,
        'province':province,
        'number':number,
        'cartype':cartype,
        'ferry':ferry,
        'roadaggregation':roadaggregation,
        'nosteps': nosteps,
        'sig':sig,
        'output':output,
        'callback':callback,
        'extensions':extensions
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# #### 骑行路径规划

# In[30]:


#定义函数bicycling
def bicycling(origin, destination):
    #骑行路径规划API URL:
    url = 'https://restapi.amap.com/v4/direction/bicycling?parameters'
    params = {
        'key': zjy1022,
        'origin': origin,
        'destination': destination
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# #### 货车路径规划

# In[31]:


#定义函数truck
def truck(origin, destination, size, originid=None, destinationid=None, origintype=None, destinationtype=None, diu=None, strategy=None, waypoints=None, height=None, width=None, load=None, weight=None, axis=None, province=None, number=None, cartype=None, avoidpolygons=None, showpolyline=None, nosteps=None):
    #货车路径规划API URL：
    url = 'https://restapi.amap.com/v4/direction/truck?parameters'
    params = {
        'key': zjy1022,
        'origin': origin,
        'destination':destination,
        'size': size,
        'originid':originid,
        'destinationid':destinationid,
        'origintype':origintype,
        'destinationtype':destinationtype,
        'diu': diu,
        'strategy':strategy,
        'waypoints': waypoints,
        'height': height,
        "weight": weight,
        'width': width,
        'load': load,
        'axis': axis, 
        'province':province,
        'number':number,
        'cartype':cartype,
        'avoidpolygons':avoidpolygons,
        'showpolyline': showpolyline,
        'nosteps': nosteps       
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 距离测量

# In[14]:


#定义函数distance
def distance(origins, destination, type=None, sig=None, output=None, callback=None):
    #距离测量API URL：
    url = 'https://restapi.amap.com/v3/distance?parameters'
    params = {
        'key': zjy1022,
        'origins': origins,
        'destination': destination,
        'type': type,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 行政区域查询

# In[15]:


#定义函数administration
def administration(keywords=None, subdistrict=None, page=None, offset=None, extensions=None, filter=None, callback=None, output=None):
    #行政区域查询API服务地址：
    url = 'https://restapi.amap.com/v3/config/district?parameters'
    params ={
        'key': zjy1022,
        'keywords': keywords,
        'subdistrict': subdistrict,
        'page': page,
        'offset': offset,
        'extensions': extensions,
        'filter': filter,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 关键字搜索

# In[16]:


#定义函数text
def text(keywords, types, city=None, citylimit=None, children=None, page=None, extensions=None, sig=None, output=None, callback=None):
    #关键字搜索API服务地址：
    url = 'https://restapi.amap.com/v3/place/text?parameters'
    params = {
        'key': zjy1022,
        'keywords': keywords,
        'types': types,
        'city': city,
        'citylimit': citylimit,
        'children': children,
        'page': page,
        'extensions': extensions,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 周边搜索

# In[17]:


#定义函数around
def around(location, keywords=None, types=None, city=None, redius=None, sortrule=None, offset=None, page=None, extensions=None, sig=None, output=None, callback=None):
    #周边搜索API服务地址：
    url = 'https://restapi.amap.com/v3/place/around?parameters '
    params = {
        'key': zjy1022,
        'location': location,
        'keywords': keywords,
        'types': types,
        'city': city,
        'redius': redius,
        'sortrule': sortrule,
        'offset': offset,
        'page': page,
        'extensions': extensions,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 多边形搜索

# In[18]:


#定义函数polygon
def polygon(polygon, keywords= None, types=None, offset=None, page=None, extensions=None, sig=None, output=None, callback=None):
    #多边形搜索API服务地址：
    url = 'https://restapi.amap.com/v3/place/polygon?parameters '
    params = {
        'key': zjy1022,
        'polygon': polygon,
        'keywords': keywords,
        'types': types,
        'offset': offset,
        'page': page,
        'extensions': extensions,
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### ID查询

# In[19]:


#定义函数id
def detail(id, sig=None, output=None, callback=None):
    #ID查询搜索API服务地址：
    url = 'https://restapi.amap.com/v3/place/detail?parameters'
    params = {
        'key': zjy1022,
        'id': id,
        'output': output,
        'sig': sig,
        'callback': callback
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### IP定位

# In[20]:


#定义函数iipp
def iipp(ip=None, sig=None, output='JSON'):
    url = 'https://restapi.amap.com/v3/ip?parameters'
    params = {
        'key': zjy1022,
        'ip': ip,
        'sig': sig,
        'output': output
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 静态地图

# In[21]:


#定义函数staticmap
from PIL import Image
from io import BytesIO
def staticmap(location, zoom, size=None, scale=1, markers=None, labels=None, paths=None, traffic=None, sig=None):
    url = 'https://restapi.amap.com/v3/staticmap?parameters'
    params = {
        'key': zjy1022,
        'location': location,
        'zoom': zoom,
        'size': size,
        'scale': scale,
        'markers': markers,
        'labels': labels,
        'paths': paths,
        'traffic': traffic,
        'sig': sig
        
    }
    response = requests.get(url, params=params)
    data = Image.open(BytesIO(response.content))
    return data


# ### 坐标转换

# In[22]:


#定义函数coordinate
def coordinate(locations, coordsys=None, sig=None, output=None):
    #坐标转换API服务地址：
    url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    params = {
        'key': zjy1022,
        'locations': locations,
        'coordsys': coordsys,
        'sig': sig,
        'output': output
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 天气查询

# In[23]:


#定义函数weather
def weather(city, extensions=None, output=None):
    #天气查询API服务地址：
    url = "https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
        'key': zjy1022,
        'city': city,
        'extensions': extensions,
        'output': output
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


# ### 输入提示

# In[24]:


#定义函数inputtips
def inputtips(keywords, type=None, location=None, city=None, citylimit=None, datatype=None, sig=None, output=None, callback=None):
    #输入提示API服务地址：
    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'
    params = {
        'key': zjy1022,
        "keywords": keywords,
        'type': type,
        'location': location,
        'city': city,
        'citylimit': citylimit,
        'datatype': datatype, 
        'sig': sig,
        'output': output,
        'callback': callback
    }
    response = requests.get(url, params)
    data = response.json()
    return data


# In[ ]:




